<!DOCTYPE HTML>
<html>
<head>
    <title>我的购物车</title>
    <link href="css/cart.css" rel="stylesheet" type="text/css">
    <link href="css/cart/common.css" rel="stylesheet" type="text/css">
    <link href="css/cart/main.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="css/foot.css"/>
    <link rel="stylesheet" href="css/head.css"/>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="js/base-v1.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-1.2.6.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/common.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="s/base-2011.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-extend.js"></script>
    <script type="text/javascript" src="js/lib-v1.js" charset="utf-8"></script>
    <link href="css/prodList.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/logout.js"></script>
    <meta charset="UTF-8">
    <script type="text/javascript">
        $(function(){
            // alert("好啊1");
            var userId="";
            var _ticket = $.cookie("EM_TICKET");
            if(!_ticket){
                window.location.href="login.html";
                return ;
            }
            //当dataType类型为jsonp时，jQuery就会自动在请求链接上增加一个callback的参数
            $.ajax({
                url : "http://www.easyhouse.com/user/query/" + _ticket,
                dataType : "json",
                type : "GET",
                success : function(data){

                    if(data.status == 200){
                        var _data = JSON.parse(data.data);//jackson
                        if(_data==null){
                            alert("啥也别说了，你的用户超时了,赶紧查查redis还有数据没有");
                            window.location.href="./login.html";
                            return;}
                        var html =_data.userName+"，欢迎来到好房！<a href=\"javascript:void(0)\" class=\"link-logout\" onclick='logout()'>[退出]</a>  \|<a href=\"http://www.easyhouse.com/manage.html\" class=\"link-logout\">[后台]</a>";
                        userId=_data.userId;
                        $("#loginbar").html(html);
                        query(userId);
						var element = document.getElementById("userName");
						element.setAttribute("value",_data.userName);
                    }else{
                        alert("咋了兄弟，购物车没东西自己心里没数吗，赶紧购物去");
                    }
                },
                error : function(){
                    alert('index error.');
                }
            });
        });
        function del(productId,userId){
            if(productId==null||userId==null){
                alert("删除参数有误");
                return ;
            }
            if(confirm("您确定删除吗？")){
                $.ajax({
                    url:"http://www.easyhouse.com/cart/delete?productId="+productId+"&userId="+userId,
                    dataType:"json",
                    type:"GET",
                    success:function (data) {
                        if(data.status==200){
                            window.location.href="http://www.easymall.com/mycart.html";
                        }else{
                            alert("删除有问题");
                        }
                    },
                    error:function () {
                        alert("删除发送失败");
                    }
                });

            }
        }
        function inputNum(productId,userId){

            var num=document.getElementById(productId).value;
            var numOld=document.getElementById("hid_"+productId).value;
            if(num==""||num==null){
                alert("num填写错误");
                return;
            }
            if(num==numOld){
                alert("没有变化数值");
                return;
            }
            if(num>200){
                alert("购买数量最大200");
                return;
            }
            $.ajax({
               url:"http://www.easyhouse.com/cart/update?productId="+productId+"&userId="+userId+"&num="+num,
                dataType:"json",
               type:"GET",
                success:function (data) {
                    if(data.status==200){
                        window.location.href="./mycart.html";
                    }else{
                        alert("更新返回的不是成功数据");
                    }
                },
                error:function () {
                    alert("咋回事，改个num还能出错，没访问到cart系统吧兄弟");
                }
            });
        }
        function query(userId){
            $.ajax({
                url:"http://www.easyhouse.com/cart/query?userId="+userId,
                dataType:"json",
                type:"GET",
                success:function(data){
                    if(data.length>0){
                        var money=0;
                        $.each(data,function(index, cart){
                            var productId=cart.houseId;
                            var productName=cart.houseName;
                            var productPrice=cart.productPrice;
                            var productImage=cart.imgUrl;
                            var num=cart.houseArea;
                            var prodHtml="product-info.html?productId="+productId;
                            var inputId="hid_"+productId;
                            var itemMoney=productPrice*num;
							var Province=cart.addrProvince;
							var District=cart.addrDistrict;
							var houseDescription=cart.houseDescription;
							var element = document.getElementById("userName");
							var userName = element.getAttribute("value");
							var userId = cart.userId;
							var consumeId = cart.consumerId;
							console.log($.trim(userName) == $.trim(userId));
                            money=money+itemMoney;
							if(cart.sellStatus==0&&$.trim(userName)==$.trim(userId)){
								$("#carts1").append("<li><a href='"+
								prodHtml+"' target='_blank' class='fl pic'><img src='"+
								productImage+"' ></a><div class='fr all-info'><div class='fl basic-info'><p class='name'><a href='"+
								prodHtml+"' target='_blank'>"+productName+"</a></p><p class='region'>[<a href='"+prodHtml+"'>"+
								Province+"</a>|<a href='"+prodHtml+"'>"+District+"</a>]</p><p class='details'><span>"+
								houseDescription+"</span></p><p class='total'>面积"+
								num+"</p></div><div class='fr price-info'><div class='fl average-price'>成交价<span><label>"+
								productPrice+"</label>一共</span></div></div><div class='clear'></div></div><a class='del-fav actDelFollow' href='"+
								prodHtml+"'>查看详情</a></li>");
							}
							if(cart.sellStatus!=0&&$.trim(userName)==$.trim(userId)){
								$("#carts2").append("<li><a href='"+
								prodHtml+"' target='_blank' class='fl pic'><img src='"+
								productImage+"' ></a><div class='fr all-info'><div class='fl basic-info'><p class='name'><a href='"+
								prodHtml+"' target='_blank'>"+productName+"</a></p><p class='region'>[<a href='"+prodHtml+"'>"+
								Province+"</a>|<a href='"+prodHtml+"'>"+District+"</a>]</p><p class='details'><span>"+
								houseDescription+"</span></p><p class='total'>面积"+
								num+"</p></div><div class='fr price-info'><div class='fl average-price'>成交价<span><label>"+
								productPrice+"</label>一共</span></div></div><div class='clear'></div></div><a class='del-fav actDelFollow' href='"+
								prodHtml+"'>查看详情</a></li>");
							}
							if(cart.sellStatus!=0&&$.trim(userName)==$.trim(consumeId)){
								$("#carts3").append("<li><a href='"+
								prodHtml+"' target='_blank' class='fl pic'><img src='"+
								productImage+"' ></a><div class='fr all-info'><div class='fl basic-info'><p class='name'><a href='"+
								prodHtml+"' target='_blank'>"+productName+"</a></p><p class='region'>[<a href='"+prodHtml+"'>"+
								Province+"</a>|<a href='"+prodHtml+"'>"+District+"</a>]</p><p class='details'><span>"+
								houseDescription+"</span></p><p class='total'>面积"+
								num+"</p></div><div class='fr price-info'><div class='fl average-price'>成交价<span><label>"+
								productPrice+"</label>一共</span></div></div><div class='clear'></div></div><a class='del-fav actDelFollow' href='"+
								prodHtml+"'>查看详情</a></li>");
							}
                        })
                       document.getElementById("span_2").innerText=money+"￥";
                        //alert(money);
                    }else{
                        alert("你是不是没登陆啊");
                    }
                }
            });
        }
        function search(a){
            var query=document.getElementById(a).value;
           // alert(query);
            window.location.href="./search.html?query="+query;

        }
    </script>
</head>
<body>
<div id="common_head">
    <div id="line2">
        <img id="logo" src="img/head/logo.jpg"/>
        <input type="text" value="" accesskey="s" id="key" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) search('key');"/>
        <input type="button" value="搜 索" onclick="search('key')"/>
        <span id="goto">
			<a id="goto_cart" href="./mycart.html">我的房源</a>
			<a id="goto_cart" href="./talk.html">发起聊天</a>
		</span>
        <img id="erwm" src="img/head/qr.jpg"/>
    </div>
	<header class="lianjia-header"><div class="nav-wrap"><div class="wrapper"><div class="fl"><a href="https://www.lianjia.com/" class="logo"></a></div><div class="fr nav"><div class="fl"><ul>
	                              <li>
	                <a class="" href="./product-list.html?page=1&rows=5">全部房源</a>
	            </li>
	                                              <li>
	                <a class="" href="/web/sekill/list">新房</a>
	            </li>
	                                              <li>
	                <a class="" href="https://cq.lianjia.com/zufang/">租房</a>
	   
	                                  <li class="hover">
	              <a class="" href="https://cq.lianjia.com/wenda/">
	              指南
	              </a>
	              <div class="nav-list">
	                  <dd>
	                      <i></i>
	                                                                                  <dl>
	                                    <a href="https://cq.lianjia.com/wenda/">问答</a>
	                                </dl>
	                                                                                                                <dl>
	                                    <a href="https://news.lianjia.com/cq/baike/">百科</a>
	                                </dl>
																			</dd>
	              </div>
	          </li>
	                                    <li>
	                <a class="" href="https://cq.lianjia.com/tool.html" target="_blank">工具</a>
	            </li>
	                                              <li>
	                <a class="" href="https://cq.lianjia.com/yezhu/" target="_blank">发布房源</a>
	            </li>
				<li class="fore1" id="loginbar" clstag="homepage|keycount|home2013|01b">
				    <span id="head_span"\\\x><a href="login.html">登录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="regist.html">注册</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="manage.html">后台</a></span>
				
				</li>
	                  </ul></div><div class="fr login"><div class="login-panel typeUserInfo"></div></div></div></div></header>
    
</div>
<div class="warp">

    <!-- 标题信息 -->
    <div id="title">
        <span id="title_checkall_text">在售房源</span>
<!--        <span id="title_name">商品</span>
        <span id="title_price">单价（元）</span>
        <span id="title_buynum">数量</span>
        <span id="title_money">小计（元）</span>
        <span id="title_del">操作</span> -->
    </div>
    <!-- 购物信息 
    <div id="carts">

    </div>-->
	<div class="community-list" node-type="list" style="margin:0px auto">
		<ul id="carts1" style="margin:0px auto">
			
        </ul>
	</div>
	<!-- 标题信息 -->
	    <div id="title">
	        <span id="title_checkall_text">已售出房源</span>
	<!--        <span id="title_name">商品</span>
	        <span id="title_price">单价（元）</span>
	        <span id="title_buynum">数量</span>
	        <span id="title_money">小计（元）</span>
	        <span id="title_del">操作</span> -->
	    </div>
	    <!-- 购物信息 
	    <div id="carts">
	
	    </div>-->
		<div class="community-list" node-type="list" style="margin:0px auto">
			<ul id="carts2" style="margin:0px auto">
				
	        </ul>
		</div>
		<!-- 标题信息 -->
		    <div id="title">
		        <span id="title_checkall_text">已购买房源</span>
		<!--        <span id="title_name">商品</span>
		        <span id="title_price">单价（元）</span>
		        <span id="title_buynum">数量</span>
		        <span id="title_money">小计（元）</span>
		        <span id="title_del">操作</span> -->
		    </div>
		    <!-- 购物信息 
		    <div id="carts">
		
		    </div>-->
			<div class="community-list" node-type="list" style="margin:0px auto">
				<ul id="carts3" style="margin:0px auto">
					
		        </ul>
			</div>
    <!-- 总计条 -->
    <div id="total">
	<!-- 总计条 
        <div id="total_1">
            <input name="allC" type="checkbox" value=""/>
            <span>全选</span>
            <a id="del_a" href="#">删除选中的商品</a>
            <span id="span_1">总价：</span>
            <span id="span_2"></span>
        </div>
        <div id="total_2">
            <a id="goto_order" href="./myorder-cart.html">去结算</a>
        </div>
		-->
    </div>
	<input hidden="hidden" id="userName" name="userName" value="" />
</div>
<div id="common_foot">
    <p>
        Copyright © 2011-2015 达内软件技术有限公司 版权所有 保留一切权利 苏B2-20130048号 | 京ICP备09062682号-9
        <br>
        网络文化经营许可证苏网文[2012]0401-019号
    </p>
</div>
</body>
</html>